﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace PerfTestLib.Utility
{
    public static class TestFileUtility
    {
        public static string GetTestSpecIterationOutputFileName(string specId, string iterationId, int index, DateTime date)
        {
            string fileName = string.Format(@"{0}-{3}-Iteration-{1}-{2}.csv", specId, iterationId, index, date.ToString("yyyyMMdd_HH_mm_ss"));
            return fileName;
        }

        public static string GetTestSpecIterationOutputFileLocation(string specId, string iterationId, int index, DateTime date, bool createDirectory)
        {
            // results directory
            string dir = GetTestOutputDirectory(createDirectory);

            // file name
            string fileName = GetTestSpecIterationOutputFileName(specId, iterationId, index, date);

            // directory + file name
            string path = Path.Combine(dir, fileName);

            return path;
        }

        public static string GetTestSpecOutputFileName(string specId, DateTime date)
        {
            string fileName = string.Format("{0}-{1}-Spec.csv", specId, date.ToString("yyyyMMdd_HH_mm_ss"));
            return fileName;
        }

        public static string GetTestSpecOutputFileLocation(string specId, DateTime date, bool createDirectory)
        {
            // results directory
            string dir = GetTestOutputDirectory(createDirectory);

            // file name
            string fileName = GetTestSpecOutputFileName(specId, date);

            // directory + file name
            string path = Path.Combine(dir, fileName);

            return path;
        }

        public static string GetTestOutputDirectory(bool createDirectory)
        {
            // results directory
            string dir = Path.Combine(new FileInfo(Assembly.GetEntryAssembly().Location).Directory.FullName, "Results");

            if (createDirectory && Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }

            return dir;
        }
    }
}
